package com.prs.crm.dao.cdxh.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cdxh.SerialNumberssDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cdxh.SerialNumberss;
import com.prs.crm.domain.cdxh.production.ProvideRegime;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-3 下午04:52:17
 * 简单说明
 */

public class SerialNumberssDaoImpl extends BaseDaoImpl<SerialNumberss>
		implements SerialNumberssDao {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public SerialNumberss getSerialNumberss(final String styCategory) {
		return (SerialNumberss)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(SerialNumberss.class);
				        	criteria.add(Restrictions.eq("styCategory", styCategory));
				        	List<SerialNumberss> result = criteria.list();
				        	if(result.size()==0){
				        		return null;
				        	}else{
				        	return result.get(0);
				        	}
				        }   
				 } );
	}

	@Override
	public void setNumCode(SerialNumberss serialNumberss) {
		// TODO Auto-generated method stub
		 this.getHibernateTemplate().saveOrUpdate(serialNumberss);
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public SerialNumberss getSerialNumberssDis(final String styCategory) {
		return (SerialNumberss)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(SerialNumberss.class);
				        	criteria.add(Restrictions.eq("styNumberCode",styCategory));
				        	criteria.add(Restrictions.eq("judgStyle","PS"));
				        	List<SerialNumberss> result = criteria.list();
				        	if(result.size()==0){
				        		return null;
				        	}else{
				        	return result.get(0);
				        	}
				        }   
				 } );
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public SerialNumberss getSerialNumberssOrder(final String name,final String cathy) {
		return (SerialNumberss)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(SerialNumberss.class);
				        	criteria.add(Restrictions.eq("judgStyle",name));
				        	criteria.add(Restrictions.eq("styCategory",cathy));
				        	List<SerialNumberss> result = criteria.list();
				        	if(result.size()==0){
				        		return null;
				        	}else{
				        	return result.get(0);
				        	}
				        }   
				 } );
	}

}
